<?php

/*
 * CopyRight  : (C)2012-2099 HaoTeam Inc.
 * Document   : Map.php
 * Created on : 2022-12-25 16:23:15
 * Author     : Tiger <1192851302@qq.com>
 * Description: This is NOT a freeware, use is subject to license terms.
 *              这即使是一个免费软件,使用时也请遵守许可证条款,得到当时人书面许可.
 *              未经书面许可,不得翻版,翻版必究;版权归属 HaoTeam Inc;
 */

namespace app\api\controller;

use app\Request;
use haoteam\service\UtilService;
use haoteam\service\HttpService;

/**
 * 
 * Class Map
 * Tiger <1192851302@qq.com> 2022-12-25 16:23:15
 */
class Map {

    /**
     * 逆地址解析
     * @author Tiger <1192851302@qq.com>
     * @param Request $request
     * @return type
     */
    public function geocoder(Request $request) {
        [$lng, $lat] = UtilService::postMore(['longitude', 'latitude'], $request, true);
        $result = HttpService::instance()->get('https://apis.map.qq.com/ws/geocoder/v1/', [
            'key' => 'UAEBZ-OAE6J-HOVF3-F7H7W-LDFGQ-5OBGY',
            'location' => $lat . ',' . $lng
        ]);
        if ($result['status'] == 0) {
            return app('json')->successful($result['result']);
        }
        return app('json')->fail($result['message']);
    }

}
